package com.example.backend.mapper;


import com.example.backend.pojo.Complain;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ComplainMapper {
    @Select("select * from complain,foodorder where complain.orderid=foodorder.orderid and foodorder.userid= #{userid}")
    List<Complain> getallbyuserid(Integer userid);

    @Insert("INSERT INTO complain(orderid,complain,image,createtime,state)    VALUES (#{orderid},#{complain},#{image},now(),0)")
    @Options(useGeneratedKeys = true, keyProperty = "complainid")
    void addcomplain(Complain complain);

    @Update("update complain set state=#{state} where complainid=#{complainid}")
    void statechange(@Param("complainid")Integer complainid, @Param("state")Integer state);

    @Select("select * from complain,foodorder where foodorder.complainid=complain.complainid and complain.state =#{state} and foodorder.restaurantid like #{restaurantid}")
    List<Complain> getstate(@Param("restaurantid")String restaurantid,@Param("state")Integer state);

    @Update("update complain set state=3,reply=#{reply},supplement=#{supplement} where complainid=#{complainid}")
    void accept(Complain complain);

    @Update("update complain set  complain=#{complain},image=#{image},createtime=now(),state=0  where complainid=#{complainid}")
    void retry(Complain complain);

    @Select("select  * from complain where complainid=#{complainid}")
    Complain getByid(Integer complainid);
}
